/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import java.io.IOException;
import java.io.PrintWriter;

public abstract class ChildlessPageElement extends PageElement {

	public ChildlessPageElement() {
		super();
	}

	public ChildlessPageElement(final String _controlId) {
		super(_controlId);
	}

	/**
	 * Provides the render for all elements that don't have children.
	 * @throws IllegalStateException if the load() wasn't called first.
	 */
	@Override
	public void render() throws IllegalStateException, IOException {
		if (!this.wasLoaded()) { throw new IllegalStateException(this.getClass() + "was not initialized"); }
		final PrintWriter writer = this.getWriter();

		final String renderAttribute = this.renderAttribute();
		if (this.isPrettyPrint()) {
			for (int i = 0; i < this.getTabsIn(); i++) {
				writer.print("\t");
			}
		}
		writer.println("<" + this.getTag() + " " + renderAttribute + "/>");
	}
}
